home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // Copyright (c) 2002, Colin Granville
- //
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or
- // without modification, are permitted provided that the following
- // conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following
- // disclaimer in the documentation and/or other materials
- // provided with the distribution.
- //
- // * The name Colin Granville may not be used to endorse or promote
- // products derived from this software without specific prior
- // written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- // OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //--------------------------------------------------------------------------
-
- #ifndef GuiObject_h
- #define GuiObject_h
-
- #include "GuiToolbox.h"
- #include "stl:string.h"
- #include "GuiWimp.h"
-
- class GuiObject
- {
- public:
- enum {ShowAsMenu=1,ShowAsSubmenu=2,ShowAsSubwindow=4}; //flags
- enum {ShowTypeDefault = 0, ShowTypeFullSpec = 1, ShowTypeTopLeft =2};
-
- GuiObject(const char* name);
- GuiObject(GuiObjectId id); // Only reference created -
- // Toolbox object not destroyed when GuiObject is deleted
- virtual ~GuiObject();
-
- GuiObjectId id() const {return m_id;}
- void show(int flags, int show_type,const void* type,
- const GuiObject* parent,
- GuiComponentId parent_component);
- void hide();
- bool isShowing() const;
-
-
-
- protected:
- int getValue(int method_code,int fail_value=0) const;
- bool getValue(int method_code,void *value) const;
- void setValue(int method_code,int value);
- void setValue(int method_code,const void* value);
- string getString(int method_code) const;
- void setString(int method_code,const char* str);
-
- private:
- GuiObjectId m_id;
- int m_auto_delete;
-
- void operator=(); // no copying - not defined
- GuiObject(const GuiObject&); // no copying - not defined
- };
-
- struct GuiTopLeft //returned in some toolbox events
- {
- int x;
- int y;
- };
-
- struct GuiShowObjectBlock //returned in some toolbox events
- {
- GuiBBox visibleArea;
- int xscroll;
- int yscroll;
- int behind;
- };
-
- struct GuiObjectAboutToBeShown : public GuiToolboxEventHeader
- {
- int showType;
- union
- {
- GuiTopLeft pos;
- GuiShowObjectBlock full;
- }info;
- };
-
- //********************************************************************************
-
- class GuiWindowObject : public GuiObject
- {
- public:
- enum {ShowDefault = 0, ShowFullSpec = 1, ShowTopLeft =2};
- GuiWindowObject(const char* name) : GuiObject(name) {}
- GuiWindowObject(GuiObjectId id) : GuiObject(id) {}
- ~GuiWindowObject();
-
- void show(const GuiTopLeft& top_left,
- const GuiObject* parent=0,
- GuiComponentId parent_component_id=NULL_GuiComponentId);
-
- void show(const GuiGetWindowStateBlock& full_spec,
- const GuiObject* parent=0,
- GuiComponentId parent_component_id=NULL_GuiComponentId);
-
- void showCentred(int offset_x=0,int offset_y=0,
- const GuiWindowObject* centre_in_this_window=0,
- const GuiObject* parent=0,
- GuiComponentId parent_component_id=NULL_GuiComponentId);
-
-
-
- void showAsMenu(const GuiGetWindowStateBlock& full_spec,
- const GuiObject& parent,
- GuiComponentId parent_component_id=NULL_GuiComponentId);
-
- void showAsMenuAtPointer(const GuiObject& parent,
- GuiComponentId parent_component_id=NULL_GuiComponentId,
- const GuiTopLeft* pointer_offset=0);
-
- void showAsMenuCentred(const GuiObject& parent,
- const GuiWindowObject* centre_in_this_window=0,
- GuiComponentId parent_component_id=NULL_GuiComponentId);
-
- protected:
- virtual GuiObjectId underlyingWindowId() const = 0;
-
- private:
- void showAtPointer(int flags,
- const GuiObject* parent,
- GuiComponentId parent_component_id,
- const GuiTopLeft* offset);
- void showCentred(int flags,
- int offset_x,int offset_y,
- const GuiWindowObject* centre_in_this_window,
- const GuiObject* parent,
- GuiComponentId parent_component_id);
- };
-
-
- //********************************************************************************
-
- class GuiMenuObject : public GuiObject
- {
- public:
- GuiMenuObject(const char* name) : GuiObject(name) {};
- GuiMenuObject(GuiObjectId id) : GuiObject(id) {}
-
- void show(const GuiTopLeft& top_left,
- const GuiObject& parent,
- GuiComponentId parent_component_id=NULL_GuiComponentId);
-
- };
-
- //********************************************************************************
- // Window Object Inlines
- //********************************************************************************
-
- inline void GuiWindowObject::show(const GuiTopLeft& top_left,
- const GuiObject* parent,
- GuiComponentId parent_component_id)
- {
- GuiObject::show(0,GuiObject::ShowTypeTopLeft,&top_left,parent,parent_component_id);
- }
-
- //********************************************************************************
-
- inline void GuiWindowObject::show(const GuiGetWindowStateBlock& full_spec,
- const GuiObject* parent,
- GuiComponentId parent_component_id)
- {
- GuiObject::show(0,GuiObject::ShowTypeFullSpec,&full_spec.visibleArea,
- parent,parent_component_id);
- }
-
-
- //********************************************************************************
-
- inline void GuiWindowObject::showCentred(int offset_x,int offset_y,
- const GuiWindowObject* centre_in_this_window,
- const GuiObject* parent,
- GuiComponentId parent_component_id)
- {
- showCentred(0,offset_x,offset_y,
- centre_in_this_window,parent,parent_component_id);
- }
-
- //********************************************************************************
-
- inline void GuiWindowObject::showAsMenu(const GuiGetWindowStateBlock& full_spec,
- const GuiObject& parent,
- GuiComponentId parent_component_id)
- {
- GuiObject::show(GuiObject::ShowAsMenu,GuiObject::ShowTypeFullSpec,
- &full_spec.visibleArea,&parent,parent_component_id);
- }
-
- //********************************************************************************
-
- inline void GuiWindowObject::showAsMenuAtPointer(const GuiObject& parent,
- GuiComponentId parent_component_id,
- const GuiTopLeft* pointer_offset)
- {
- showAtPointer(GuiObject::ShowAsMenu,&parent,parent_component_id,pointer_offset);
- }
-
- //********************************************************************************
-
- inline void GuiWindowObject::showAsMenuCentred(const GuiObject& parent,
- const GuiWindowObject* centre_in_this_window,
- GuiComponentId parent_component_id)
- {
- showCentred(GuiObject::ShowAsMenu,0,0,
- centre_in_this_window,&parent,parent_component_id);
- }
-
- //********************************************************************************
- // MENUOBJECT inlines
- //********************************************************************************
-
- inline void GuiMenuObject::show(const GuiTopLeft& top_left,
- const GuiObject& parent,
- GuiComponentId parent_component_id)
- {
- GuiObject::show(GuiObject::ShowAsMenu,GuiObject::ShowTypeTopLeft,
- &top_left,&parent,parent_component_id);
- }
-
- #endif
-